1. Field of the Invention
The present invention relates to the field of data processing. In particular, the invention relates to saving register values from registers to a backup data store, and restoring the register values from the backup data store to the registers.
2. Background to the Invention
A data processing apparatus may have a set of registers for storing data values used by the processor during processing. The register values represent the current state of the processor. When the processing apparatus encounters a context switch, then at least some of the register values stored in the registers may be stored to a backup data store. Following the change of context, different register values may be stored in the registers. When the process associated with the context switch has finished, the original register values may be restored to the registers in order to complete execution of the process which was interrupted by the context switch.
On occurrence of an event which triggers the saving of register state to the backup data store (e.g. an exception event), a currently executing operation may not yet have completed. The operation may take a number of processing cycles to execute. If the operation writes a result value to one of the registers, and the state saving operation is started before the currently executing operation has completed, then the register state written to the backup data store may not include the recently calculated result value. This means that processing errors may occur after restoring the state data. Data dependency hazards, where a value of a register is read before the result value is written to the register, should be avoided.
It is generally desirable that the time between the occurrence of the state saving trigger event and the end of the state saving process is predictable. This is especially the case in safety-critical systems, such as car braking systems, where it is important that the interrupt latency is constant and short. If the currently executing operation was allowed to complete before starting the state saving operation, then the data dependency hazard would be avoided. However, since the state saving trigger event may have occurred at any point during the execution of the currently executing operation, the delay in starting the state saving process will vary depending on the execution point at which the trigger event occurred and so it is difficult to predict how long it will take before all of the state data is saved to the backup data store. Allowing execution of the currently executing operation to complete before starting the state saving operation would also increase the interrupt latency. Therefore, starting the state saving operation only after the currently executing operation is complete is not appropriate in many systems.
Another way of avoiding data dependency hazards is to abandon the currently executing instruction midway through its execution on occurrence of a state saving trigger event. However, this option suffers from the disadvantage that after the state is restored the abandoned instruction will need to be executed again in its entirety, and so this slows the forward progress of program execution by the processing apparatus. Furthermore, the abandoned instruction may not be idempotent.
These techniques each suffer from one of the following disadvantages: data dependency hazards, unpredictable and slow exception handling latency, and slow processing after restoring the register state. The present invention seeks to provide an improved state saving and restoring mechanism which avoids data dependency hazards, has a predictable latency, and does not delay processing after the state has been restored to the registers.